using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace Botanicraft
{
    public class TreeCreator2D : MonoBehaviour
    {
        Dictionary<int, Tree2D> trees;
        int currentId;

        public Texture2D bark;
        public Texture2D barkNormal;
        public Texture2D leaf;

        public float growDist;
        public float maxDist;
        public float minDist;

        // Use this for initialization
        void Start()
        {
        }

        // Update is called once per frame
        void Update()
        {

        }

        public TreeCreator2D()
        {
            trees = new Dictionary<int, Tree2D>();
            currentId = 0;
        }

        public void CreateTree(int treeType, Vector3 position, bool createUnique = false, float growDist = 1f, float maxDist = 2f, float minDist = 1.5f)
        {
            if (createUnique)
            {
                for (int i = 0; i < trees.Count; i++)
                {
                    trees[i].finished = true;
                    trees[i].branches.Clear();
                    trees[i].leaves.Clear();
                    Destroy(trees[i].treeObject);
                    //Destroy(trees[i]);
                    trees.Remove(i);
                    currentId--;
                }
            }
            Tree2D tree = new Tree2D(treeType, Vector3.zero, currentId++, bark, barkNormal, leaf, growDist, maxDist, minDist);
            trees.Add(tree.id, tree);
        }

        public void CreateTree(List<Leaf2D> leaves)
        {
            //Tree tr
        }

        public void DestroyTree(Tree2D tree)
        {
            tree.finished = true;
            tree.branches.Clear();
            tree.leaves.Clear();
            //Destroy(tree);
        }

        public void PlaceSeed(Vector3 position)
        {

        }

        public void PlaceCrown(Vector3 position)
        {

        }
    }
}
